package com.wefans.wefansapp.common.tool.popup;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.wefans.wefansapp.R;

public class LoginDialog extends BaseDialog {

	private Button mBtnClose = null;
	private EditText mEtId = null;
	private EditText mEtPassword = null;
	private Button mBtnLogin = null;
	private CheckBox mChkAutoLogin = null;
	private Button mBtnSearchId = null;
	private Button mBtnSearchPassword = null;
	
	private OnLoginListener mLoginListener = null;
	
	public interface OnLoginListener {
		void onLoginInfo(String strId, String strPassword, boolean bAutoLogin);
		void onFindId();
		void onFindPassword();
	}
	
	public LoginDialog(Context mContext, OnLoginListener loginListener) {
		super(mContext);
		
		setContentView(R.layout.dialog_login);
		
		mBtnClose = (Button)findViewById(R.id.BTN_DIALOG_CLOSE);
		mEtId = (EditText)findViewById(R.id.ET_ID);
		mEtPassword = (EditText)findViewById(R.id.ET_PASSWORD);
		mBtnLogin = (Button)findViewById(R.id.BTN_LOGIN);
		mChkAutoLogin = (CheckBox)findViewById(R.id.CHK_AUTO_LOGIN);
		mBtnSearchId = (Button)findViewById(R.id.BTN_SEARCH_ID);
		mBtnSearchPassword = (Button)findViewById(R.id.BTN_SEARCH_PASSWORD);
		
		mLoginListener = loginListener;
		mBtnClose.setOnClickListener(onClickListener);
		mBtnLogin.setOnClickListener(onClickListener);
		mBtnSearchId.setOnClickListener(onClickListener);
		mBtnSearchPassword.setOnClickListener(onClickListener);
	}

	android.view.View.OnClickListener onClickListener = new android.view.View.OnClickListener() {
		
		public void onClick(View v) {
			
			switch (v.getId()) {
			case R.id.BTN_LOGIN:
				if (mLoginListener != null) {
					mLoginListener.onLoginInfo(mEtId.getText().toString(), 
							   mEtPassword.getText().toString(), 
							   mChkAutoLogin.isChecked());
				}
				dismiss();
				break;
			case R.id.BTN_SEARCH_ID:
				mLoginListener.onFindId();
				dismiss();
				break;
			case R.id.BTN_SEARCH_PASSWORD:
				mLoginListener.onFindPassword();
				dismiss();
				break;
			case R.id.BTN_DIALOG_CLOSE:
				dismiss();
				break;
			}
		}
	};

}
